package edu.nanyang.dao;

import edu.nanyang.domain.PaperInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface PaperInfoDao {
    /**
     * 查询所有试题
     *
     * @return
     */
    @Results(value = {
            @Result(property = "id", column = "id"),
            @Result(property = "questionNum", column = "question_num"),
            @Result(property = "questionContent", column = "question_content"),
            @Result(property = "questionScore", column = "question_score"),
            @Result(property = "questionAnswer", column = "question_answer"),
            @Result(property = "optionInfoList", column = "question_num", many = @Many(select = "edu.nanyang.dao.OptionInfoDao.getByQuestionNumId"))
    })
    @Select("SELECT * FROM paper_info ORDER BY question_num ASC")
    List<PaperInfo> findAll();

    //使用@Select注解指明getById方法要执行的SQL
    @Select("SELECT * FROM paper_info WHERE id=#{id}")
    PaperInfo getById(int id);
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "questionNum", column = "question_num"),
            @Result(property = "questionContent", column = "question_content"),
            @Result(property = "questionScore", column = "question_score"),
            @Result(property = "questionAnswer", column = "question_answer"),
            @Result(property = "createTime", column = "create_time"),
    })
    @Select("SELECT * FROM paper_info WHERE question_num=#{questionNumId}")
    PaperInfo getByQuestionNumId(Integer questionNumId);

    int deleteById(int id);

    int add(PaperInfo paperInfo);

    int update(PaperInfo paperInfo);
}
